#!/bin/bash

source /etc/profile
if [ $# -eq 1 ]; then
	targetHour=$1
else
	targetHour=`date -d "-1 hours" +"%Y%m%d%H"`
fi
path=$(cd $(dirname $0);pwd)
parentPath=$(dirname ${path})
targetDate=${targetHour:0:8}
day=$(date -d"${targetDate}" "+%Y-%m-%d")
echo $targetHour
analysis_job=`cat << EOF
analysis_behaviour/analysis_behaviour.sh
analysis_conversion/analysis_conversion.sh
analysis_event/analysis_event.sh
analysis_referer/analysis_referer.sh
analysis_visitors/analysis_visitors.sh
overview/overview.sh
tools/filter_ip.sh
tools/filter_keyword.sh
EOF
`
for job in ${analysis_job[@]}
do
{
	jobname=`basename ${job} .sh`
	wait
	echo "sh ${path}/${job} ${targetHour}"
	(echo "--${targetHour} begin--";sh ${path}/${job} ${targetHour};echo "--${targetHour} success--") > ${path}/logs/${jobname}.log 2>&1
}&
done
wait
if [ ${targetHour:8:2} -eq "23" ];then
	sh ${path}/analysis_quota_forecast/analysis_quota_forecast.sh ${targetHour}
fi